﻿package game 
{
	import flash.text.TextField;
	import game.exchangeddata.HashTable;
	import game.exchangeddata.SoundInfo;
	import game.exchangeddata.StageInfo;
	import flash.display.MovieClip;
	import game.interfaces.IGameView;
	import common.Utility;
	import flash.events.Event;
	import flash.net.NetConnection;
	import flash.events.NetStatusEvent;
	import flash.events.SecurityErrorEvent;
	import flash.net.Responder;	
	import game.events.EventData;
	import game.constants.ConstData;
	import game.popups.MessagePopup;
	import game.exchangeddata.LanguageInfo;
	import game.LoadXML;
	import flash.utils.setTimeout;
	import flash.external.ExternalInterface;
	import flash.utils.setInterval;
	/**
	 * ...
	 * @author Nguyen Thi Bich Phuong (Daisy)
	 */
	public class GameBase extends MovieClip {
		public var nc:NetConnection;
		public var ncId:NetConnection;

		public var defaultView:IGameView;
		public var currentView:IGameView;
		
		public var stageInfo:StageInfo;
		public var messagePopup:MessagePopup;
		// debug
		////////LOAD MENUMAIN.XML
		private var loadMenu:LoadXML;
		////////END LOAD MENU MAIN
		private var loadSound:LoadXML;
		public var sndCtr:SoundController;
		private var soundsName:String = "sounds.xml";
		
		public var clientObjectNc:Object;
		public var clientObjectNcId:Object;				
		
		public function GameBase() {
			Utility.setGame(this);
			currentView = defaultView;		
			stageInfo = new StageInfo();
			//support
			this.addEventListener(EventData.GET_REPORT, getReport);
			this.addEventListener(EventData.SHOW_ERR_DATE_NULL, getReport);
			this.addEventListener(EventData.SHOW_ERR_CHOOSE_DATE, getReport);
			this.addEventListener(EventData.GET_REPORT, getReport);
			this.addEventListener(EventData.UPDATE_DATE_FROM, updateFromToDate);
			this.addEventListener(EventData.UPDATE_DATE_TO, updateFromToDate);
			this.stageInfo.reportInfo.addEventListener(EventData.UPDATE_VALUE_REPORT, updateReportInfo);
			this.stageInfo.reportInfo.addEventListener(EventData.UPDATE_DATE_REPORT, updateDateReport);
			//support Bet status
			this.stageInfo.betStatusInfo.addEventListener(EventData.UPDATE_BET_STATUS, upateBetStatus);
			this.stageInfo.tableInfo.addEventListener(EventData.UPDATE_GAMESET_GAMENO, updateGameSetGameNo);
			
			////////LOAD MENUMAIN.XML to test
			
			this.loadMenu = new LoadXML();
			this.loadMenu.loadData("menuMain.xml");
			this.loadMenu.addEventListener(EventData.LOAD_XML_COMPLETE, loadMenuMainHdl);
			
			////////END LOAD MENU MAIN to test
			GlobalVariables.langInfo.addEventListener(EventData.HASHTABLE_COMPLETE, updateTxt);//cai nay dong k co change ngon ngu dc 
			/////////load sounds.xml
			this.loadSound = new LoadXML();
			this.loadSound.loadData(soundsName);
			this.loadSound.addEventListener(EventData.LOAD_XML_COMPLETE, loadSoundHdl);
			sndCtr = new SoundController();
			this.addEventListener(EventData.SHOW_MS, showMsHdl);
			this.addEventListener(EventData.CHANGE_PASS, getChangePassHdl);
		}		
		
		private function getChangePassHdl(e:EventData):void 
		{
			if (GlobalVariables.siteName == "corroom.com" || GlobalVariables.siteName == "wwww.corroom.com") {
				this.ncId.call("changeMGSPokerPass", new Responder(successCallFMS, failCallFMS), stageInfo.userInfo.sessionId, stageInfo.userInfo.userName, "10006", stageInfo.userInfo.newPass);
				trace("changeMGSPokerPass");
			} else {
				this.ncId.call("setNewPassword", new Responder(successCallFMS, failCallFMS), stageInfo.userInfo.sessionId, stageInfo.userInfo.oldPass, stageInfo.userInfo.newPass);
				trace("setNewPassword:" + stageInfo.userInfo.oldPass+":::"+stageInfo.userInfo.newPass );
			}
		}
		
		private function showMsHdl(e:EventData):void 
		{
			trace("vo day" + e.ms);
			this.setTimelyMessage(GlobalVariables.langInfo.hashTable.lookupString(e.ms));
		}
		
		////////LOAD MENUMAIN.XML
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function updateTxt(e:Event):void 
		{
			this.currentView.updateGameTxt(GlobalVariables.langInfo.hashTable);			
		}
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function loadMenuMainHdl(e:Event):void 
		{
			GlobalVariables.langInfo.updateInfo(this.loadMenu.xmlNode, GlobalVariables.lang);
		}
		////////END LOAD MENU MAIN
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function loadSoundHdl(e:Event):void 
		{
			this.stageInfo.soundInfo.updateInfo(this.loadSound.xmlNode, GlobalVariables.lang);
		}
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function updateGameSetGameNo(e:Event):void 
		{
			currentView.updateTableInfo(this.stageInfo.tableInfo);		
		}
		/**
		 * @author	Bmaboo
		 * @param	e
		 */
		private function getReport(e:Event):void 		{
			trace("vo getReport" + e.type);
			if(e.type == EventData.GET_REPORT)
			{
				getMemberWinLose();
			}else if(e.type == EventData.SHOW_ERR_CHOOSE_DATE)
			{
				this.messagePopup.showMessage(GlobalVariables.langInfo.hashTable.lookupString("DateRangeNAN"));
			}else if(e.type == EventData.SHOW_ERR_DATE_NULL)
			{
				this.messagePopup.showMessage(GlobalVariables.langInfo.hashTable.lookupString("PleaseInputDate"));
			}		
		}
		
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function updateFromToDate(e:Event):void 
		{
			if (e.type == EventData.UPDATE_DATE_FROM)
			{
				this.stageInfo.reportInfo.serverDateFrom = this.currentView.sendDateReportInfo(1);
			}else if (e.type == EventData.UPDATE_DATE_TO)
			{
				this.stageInfo.reportInfo.serverDateTo = this.currentView.sendDateReportInfo(2);
			}
		}
		
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function updateReportInfo(e:Event):void 
		{
			this.currentView.updateReport(this.stageInfo.reportInfo);
		}
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function upateBetStatus(e:Event):void 
		{
			trace("upateBetStatus");
			this.currentView.updateValueBetStatus(this.stageInfo.betStatusInfo);
		}
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		
		private function updateDateReport(e:Event):void 
		{
			this.currentView.updateDateReport(this.stageInfo.reportInfo.serverDateFrom, this.stageInfo.reportInfo.serverDateTo);
		}
		/**
		 * @author	Bamboo
		 * @param	info
		 */
		public function updateGameStageInfo(info:String):void {	
		}
		
		/**
		 * @author Daisy
		 */
		public function connectToNc(rtmpStr:String, roomId:String, userType:String, userName:String, pass:String, betLtdSeq:String, sessionId:String, 
									lang:String, versionNo:String, forceReload:String, isMain:String, siteName:String , casinoId:String, ncName:String, 
									ip:String, countryCode:String, loginTypeID:String, parentSID:String):void {
			//define function called by an .ASC file  
			clientObjectNc = new Object();
			clientObjectNc["setSessionToken"] = setSessionToken;
			clientObjectNc["setExpired"] = setExpired;
			clientObjectNc["setAccInfoByUserN"] = setCurrency;			
			clientObjectNc["setNewsMessage"] = setNewsMessage;
			clientObjectNc["logMeOut"] = logMeOut;			
			clientObjectNc["heartBeat"] = heartBeat;
			clientObjectNc["setMemberInfo"] = setMemberInfo;
			clientObjectNc["setErrorMessage"] = setErrorMessage;
			clientObjectNc["getClosedTables"] = setClosedTables;
			clientObjectNc["sendStatusGame"] = sendStatusGame;						
			nc =  new NetConnection();
			nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusNcHdl);
			nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHdl);
			nc.connect("rtmp://" + rtmpStr + "/"+ roomId, userType, userName, pass, betLtdSeq, sessionId, lang, versionNo, forceReload, !(isMain), siteName, 
			casinoId, ncName, ip, countryCode, loginTypeID, parentSID);
			nc.client = clientObjectNc;
		}
		
		public function setClosedTables(result:String):void
		{
			
		}
		
		/**
		 * @author Daisy
		 */
		public function connectToNcId(rtmpStr:String, roomId:String, userType:String, userName:String, sessionId:String, memberBetLtdSeq:String) {			
			//define function called by an .ASC file  
			clientObjectNcId = new Object();
			clientObjectNcId["setPlaceBet1"] = setPlaceBet1;
			clientObjectNcId["setBetStatus"] = setBetStatus;
			clientObjectNcId["showResult"] = showResult;
			clientObjectNcId["setMemberInfo"] = setMemberInfo;
			clientObjectNcId["setMemberWinLose"] = setMemberWinLose;
			clientObjectNcId["setRecentBet"] = setRecentBet;
			clientObjectNcId["setOwnUserBet"] = setOwnUserBet;
			clientObjectNcId["currentBetPool"] = currentBetPool;
			clientObjectNcId["confirmedConnection"] = confirmedConnection;
			clientObjectNcId["setTableLimit"] = setTableLimit;
			clientObjectNcId["startBet"] = startBet;
			clientObjectNcId["stopBet"] = stopBet;
			clientObjectNcId["setPlaceBet"] = setPlaceBet;
			clientObjectNcId["updateAllPersonInfo"] = updateAllPersonInfo;
			clientObjectNcId["showGameResult"] = showGameResult;
			clientObjectNcId["setServerDate2"] = setServerDate2;
			clientObjectNcId["memberCurrWinLose"] = memberCurrWinLose;
			clientObjectNcId["setAskRoute"] = setAskRoute;
			clientObjectNcId["setCardResult"] = setCardResult;
			clientObjectNcId["setCardResultDelay"] = setCardResultDelay;
			clientObjectNcId["logMeOut"] = logMeOut;
			clientObjectNcId["setErrorMessage"] = setErrorMessage;
			clientObjectNcId["setMemberLimit"] = setMemberLimit;
			clientObjectNcId["getVODId"] = setVODId;
			clientObjectNcId["showPasswordResult"] = showPasswordResult;
			clientObjectNcId["startBetInsurance"] = memberStartBetInsurance;
			clientObjectNcId["stopBetInsurance"] = memberStopBetInsurance;	
			clientObjectNcId["setAskVirtualRoute"] = setAskVirtualRoute;
			
			ncId = new NetConnection();
			ncId.addEventListener(NetStatusEvent.NET_STATUS, netStatusNcIdHdl);
			ncId.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHdl);
			ncId.connect(("rtmp://" + rtmpStr + "/" + roomId), userType, userName, sessionId, memberBetLtdSeq);
			ncId.client = clientObjectNcId;			
		}
		
		
		/**
		 * @author Daisy
		 */
		private function netStatusNcHdl(e:NetStatusEvent):void {				
			trace("netStatusNcHdl:"+e.info.code);
			switch(e.info.code) {
				case "NetConnection.Connect.Success":
					break;
				case "NetConnection.Connect.Failed":
					break;
				case "NetConnection.Connect.Rejected":
					break;
			}
		}	
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function netStatusNcIdHdl(e:NetStatusEvent):void {		
			//wtf.text = e.info.code;
			var event:EventData;
			trace("netStatusNcIdHdl:"+e.info.code);
			switch(e.info.code) {
				case "NetConnection.Connect.Success":
					/*event = new EventData(EventData.UPDATE_STATUS_ROOM_OPENED, true);				
					event.activeRoomBac = this.stageInfo.userInfo.roomId;	
					dispatchEvent(event);*/
					break;
				case "NetConnection.Connect.Failed":
					setTimelyMessage("NetConnection.Connect.Failed");
					break;
				case "NetConnection.Connect.Rejected":
					break;
				case "NetConnection.Connect.Closed":
					event = new EventData(EventData.UPDATE_STATUS_ROOM_FREE, true);				
					event.activeRoomBac = this.stageInfo.userInfo.roomId;	
					dispatchEvent(event);
					break;
			}
		}	
		
		/**
		 * @author Daisy
		 */
		private function securityErrorHdl(e:SecurityErrorEvent):void {
			trace("SecurityErrorHdl: " + e);
		}			
		
		/**
		 * @author Daisy		 
		 * @param	sessionToken
		 * @usage This function is call to get user information
		 */		
		public function callGetInfoPerson(sessionToken:String):void {
			trace("callGetInfoPerson");
			nc.call("getPersonInfo", new Responder(successCallFMS, failCallFMS), sessionToken);
			nc.call("getExpired", new Responder(successCallFMS, failCallFMS), GlobalVariables.userName, sessionToken);
			nc.call("getAccInfoByUserN", new Responder(successCallFMS, failCallFMS), sessionToken, GlobalVariables.userName);			
			//nc.call("getMemberLimit", new Responder(successCallFMS, failCallFMS), sessionToken);			
		}
		
		/**
		 * @author Daisy
		 * @param	tableId
		 * @param	sessionToken
		 * @usage This function is call to get table information
		 */
		public function callGetInfoTable(tableId:String , sessionToken:String):void {	
			ncId.call("getBetStatus", new Responder(successCallFMS, failCallFMS), tableId, sessionToken);
		}
		
		/**
		 * @author Daisy
		 * @param	sessionToken
		 * @usage This function is call to get welcome messages
		 */
		public function callGetWelcomeMessage(sessionToken:String):void {
			nc.call("getNews", new Responder(successCallFMS, failCallFMS), false, sessionToken, GlobalVariables.lang, stageInfo.userInfo.roomId);
			/*setInterval(callGetWelcomeMessage, 300000, GlobalVariables.sessionId);*/
		}
		
		/**
		 * @author Daisy
		 * @param	strMsg
		 * @usage This function is call when one function call FMS successful
		 */
		public function successCallFMS(strMsg:String):void {}
		
		/**
		 * @author Daisy
		 * @param	strMsg
		 * @usage This function is call when one function call FMS failt
		 */
		public function failCallFMS(strMsg:String):void {trace("CALL FMS FAIL")}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @author This function is call from FMS, return sessionToken
		 */
		public function setSessionToken(result:String):void {
			trace("setSessionToken:" + result);
			stageInfo.userInfo.resultSetSessionToken(result);
			dispatchEvent(new Event(EventData.CONNECT_GAME));
			callGetInfoPerson(stageInfo.userInfo.sessionId);
		}		
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is call from FMS, return member information: balance, commissionRate
		 */
		public function setMemberInfo(result:String):void {
			if (Utility.checkTokenInvalid(result)) {
				dispatchEvent(new EventData(EventData.INVALID_TOKEN, true));
			}
			else if (Utility.checkResult(result)) {				
				stageInfo.userInfo.resultSetMemberInfo(result);			
			}
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is call from FSM, return member information: isExpired
		 */
		public function setExpired(result:String):void {
			if(Utility.checkResult(result)){
				stageInfo.userInfo.resultSetExpired(result);
			}
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is call from FMS, return currency of member
		 */
		public function setCurrency(result:String):void {			
			if (Utility.checkResult(result)) {
				stageInfo.userInfo.resultCurrencySign(result);
			}
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is call from FMS, return member information: maxBet, minBet, memberLtdSeq
		 */
		public function setMemberLimit(result:String):void {	
			trace("setMemberLimit" + result)
			if(Utility.checkResult(result)){
				stageInfo.userInfo.resultSetMemberLimit(result);				
			}
		}	
		
		/**
		 * @author Daisy
		 * @param	result
		 * @param	tableNo
		 * @usage This function is call from FMS, return table information, live_bet_pool_game
		 */
		public function setBetStatus(result:String, tableNo:String):void {	
			trace("setBetStatus" + result)
			if (Utility.checkResult(result)) {
				stageInfo.tableInfo.returnSetBetStatus(result, tableNo);
			}
		}
		
		/**
		 * @author Daisy
		 * @param	minBet
		 * @param	maxBet
		 * @usage This function is used to set minBet & maxBet for table info
		 */
		public function setMinMaxTableInfo(minBet:Number, maxBet:Number):void {
			stageInfo.tableInfo.setMinMaxBet(minBet, maxBet);
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is used call from FMS, overrided in BaccaratGame
		 */
		public function currentBetPool(result:String):void {
		}
				
		public function setNewsMessage(str:String):void {
			trace("setNewsMessage" + str);
			stageInfo.welcomeMessage.setMessage(str);
		}				
		
		public function logMeOut(str:String):void {
			trace("call logMeout" + str);
			
			setTimelyMessage(GlobalVariables.langInfo.hashTable.lookupString("IdPwdMismatch"));
		}		
		
		public function confirmedConnection(str:String):void {
			callGetVODId();
			callGetWelcomeMessage(this.stageInfo.userInfo.sessionId);
			callGetInfoTable(this.stageInfo.userInfo.roomId, this.stageInfo.userInfo.sessionId);
			ncId.call("getMemberLimit", new Responder(successCallFMS, failCallFMS), this.stageInfo.userInfo.sessionId);	
			this.nc.call("getClosedTables", new Responder(successCallFMS, failCallFMS), this.stageInfo.userInfo.sessionId, GlobalVariables.userName, GlobalVariables.lang);	
			//test getRecentBet()
			//getRecentBet(1, 20);
		}
		
		public function setTableLimit(str:String):void {
			//trace("call set table Limit here!!!" + str);
			trace("tableLimit: " + parseInt(str.substr(1, 9), 10));
		}
		
		public function heartBeat():void {
			//trace("call heartBeat");
		}	
		
		public function setServerDate2(result:String):void {
			//trace("setServerDate2" + result);
		}
		
		/**
		 * @author	Bamboo
		 */
		public function getServerDate():void
		{
			this.ncId.call("getServerDate", new  Responder(successCallFMS, failCallFMS), stageInfo.userInfo.sessionId);
		}
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		public function setServerDate(result:String):void {
			this.stageInfo.reportInfo.resultServerDateTime(result);
		}
			
		/**
		 * @author	Bamboo
		 */
		public function getMemberWinLose():void {
			trace("getMemberWinLose" + this.stageInfo.reportInfo.serverDateFrom + ":" + this.stageInfo.reportInfo.serverDateTo);
			this.ncId.call("getMemberWinLose", new Responder(successCallFMS, failCallFMS), stageInfo.userInfo.sessionId, this.stageInfo.reportInfo.serverDateFrom, this.stageInfo.reportInfo.serverDateTo);
		}
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		public function setMemberWinLose(result:String):void {
			trace("setMemberWinLose");
			if(Utility.checkResult(result)){
				stageInfo.reportInfo.resultMemberWinLose(result);
			}
		}
		/**
		 * @author	Bamboo
		 * @usage This function get info for bet status
		 */
		public function getRecentBet(page:uint, numRecord:uint):void {
			//trace("getRecentBet");
			this.ncId.call("getRecentBet", new Responder(successCallFMS, failCallFMS), stageInfo.userInfo.roomId, stageInfo.userInfo.sessionId, 
			GlobalVariables.lang, page, numRecord);
			
		}
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		public function setRecentBet(result):void {
			trace("setRecentBet" + result);
			var temp:Array = result.split("&");
			if(Utility.checkResult(temp[1])){
				this.stageInfo.betStatusInfo.resultRecentBet(result);
			}
		}

		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is used call from FMS,
		 */
		public function showGameResult(result:String):void {
		}
		
		/**
		 * @author Daisy
		 * @param   gameLst
		 * @param   gameType 
		 * @param	result
		 * @usage This function is used call from FMS,
		 */
		public function sendStatusGame(InstanceName:String, gameType:String, eventType:String):void {
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @param   tableNo
		 * @usage This function is used call from FMS,
		 */
		public function showResult(result:String, tableNo:String):void {
			
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is used call from FMS,
		 */
		public function memberCurrWinLose(result:String):void {
			//HK Server
			try{
				if (Utility.checkResult(result)){
					var value:String = Utility.trim(result.substr(ConstData.LEN_SUCCESS_RESULT, ConstData.LEN_SUCCESS_BIT));					
					if (value.substr(0, 1) == "-") {
						//khong lam gi het, vo duyen
					}else if (value == "0.00"){
						var msLose:String = GlobalVariables.langInfo.hashTable.lookupString("ThisGameLose");
						setTimelyMessage(msLose);
						var strLose:String =  GlobalVariables.dirSnd + this.stageInfo.soundInfo.hashTable.lookupString("you lose");
						setTimeout(this.sndCtr.playSound, 2000, strLose, GlobalVariables.volumeSounGame);
					}else{
						var curernt:String = value;
						curernt = Utility.currency(int(curernt), 2, "");
						var msWin:String = GlobalVariables.langInfo.hashTable.lookupString("ThisGameWin") + " " + curernt;
						setTimelyMessage(msWin);
						var strWin:String = GlobalVariables.dirSnd + this.stageInfo.soundInfo.hashTable.lookupString("you win");
						setTimeout(this.sndCtr.playSound, 2000, strWin, GlobalVariables.volumeSounGame);							
					}					
				}
			}catch (e:Error) {}
			
			
			//Bavet Server
			/*try {
				if (Utility.checkResult(result)){
					var value:String = Utility.trim(result.substr(ConstData.LEN_SUCCESS_RESULT, ConstData.LEN_SUCCESS_BIT));
					
					if (value != "0.00")
					{
						
						var curernt:String;
						
						if (value.substr(0, 1) == "-") {
							curernt = value.substr(1, (value.length - 1));
							curernt = Utility.currency(int(curernt), 2, "");
							var msLose:String = GlobalVariables.langInfo.hashTable.lookupString("ThisGameLose")  + " " + curernt;
							setTimelyMessage(msLose)
							var strLose:String =  GlobalVariables.dirSnd + this.stageInfo.soundInfo.hashTable.lookupString("you lose");
							setTimeout(this.sndCtr.playSound, 2000, strLose, GlobalVariables.volumeSounGame);
						} else {
							curernt = value;
							curernt = Utility.currency(int(curernt), 2, "");
							var msWin:String = GlobalVariables.langInfo.hashTable.lookupString("ThisGameWin")  + " " + curernt;
							setTimelyMessage(msWin)							
							var strWin:String = GlobalVariables.dirSnd + this.stageInfo.soundInfo.hashTable.lookupString("you win");
							setTimeout(this.sndCtr.playSound, 2000, strWin, GlobalVariables.volumeSounGame);							
						}
					}
				}
			} catch (e:Error){}*/
			
			
		}
		
		/**
		 * @author Daisy, Bamboo
		 * @param	result
		 * @param	countDownSecond
		 * @usage This function is used call from FMS,
		 */
		public function startBet(result:String, countDownSecond:String):void {	
			//trace("startBet: " + result +"countDownSecond:" +  countDownSecond);
			if (Utility.checkResult(result)) {			
				this.stageInfo.tableInfo.returnStartBet(result);					
				this.currentView.initStartGame(int(countDownSecond));
				this.sndCtr.playSound(GlobalVariables.dirSnd + this.stageInfo.soundInfo.hashTable.lookupString("start"), GlobalVariables.volumeSounGame);
			}
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is used call from FMS,
		 */
		public function stopBet(result:String):void {
			trace("stopBet:" + result);
			this.sndCtr.playSound(GlobalVariables.dirSnd + this.stageInfo.soundInfo.hashTable.lookupString("stop"), GlobalVariables.volumeSounGame);
			this.currentView.initStopGame();
			if(GlobalVariables.autoAcceptBetting == "1") {
				this.currentView.updateBetting();
			}
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is used call from FMS,
		 */
		public function setPlaceBet(result:String):void {
			
		}

		public function updateAllPersonInfo(result:String):void {
			this.nc.call("updateAllPersonInfo", new Responder(successCallFMS, failCallFMS), GlobalVariables.userName);			
		}

		/**
		 * @author	Bamboo
		 * @param	msg
		 * @param	title
		 */
		public function showMessage(msg:String):void {
			this.messagePopup.showMessage(msg);
		}
		
		public  function setTimelyMessage(msg:String):void {
			showMessage(msg);
			setTimeout(hideMessage, ConstData.TIME_OUT_MESSAGE);
			//trace("setTimelyMessage");
		}		
		/**
		 * @author	Bamboo
		 */
		public function hideMessage():void {
			this.messagePopup.hide();
		}

		/**
		 * @author Bamboo
		 * @param	e: event that reciever from mainGame by menu
		 */
		public function receiverInfoFromMainGame(nameObj:String):void {
			trace("receiverInfoFromMainGame:" + nameObj);	
			switch(nameObj) {
				case "accountInfoBtn":
					this.currentView.initAccountInfo(this.stageInfo.userInfo);
					break;
				case "gameRuleBtn":
					this.currentView.activeGameRule(GlobalVariables.gameRuleTxt);
					break;
				case "supportBtn":
					this.currentView.activeHotLine();
					break;
				case "gameHistoryBtn":
					this.getServerDate();
					this.currentView.showReport();
					break;
				case "betStatusBtn":
					this.getRecentBet(1,20);
					this.currentView.showBetStatus();
					break;
				case "loadCompletedSWF":
					this.stageInfo.userInfo.init(GlobalVariables.userName, GlobalVariables.preUser, GlobalVariables.isMain, GlobalVariables.roomId);
					this.connectToNc(GlobalVariables.rtmpStr, "0", GlobalVariables.userType, this.stageInfo.userInfo.preUser +this.stageInfo.userInfo.userName, GlobalVariables.pass, 
					GlobalVariables.pBetLtdSeq, GlobalVariables.sessionId, GlobalVariables.lang, GlobalVariables.versionNo, 
					GlobalVariables.forceReload, this.stageInfo.userInfo.isMain, GlobalVariables.siteName, GlobalVariables.casinoId, 
					GlobalVariables.ncName, GlobalVariables.ip, GlobalVariables.countryCode, GlobalVariables.loginTypeID, GlobalVariables.parentSID);
					GlobalVariables.langInfo.updateLangInfo(GlobalVariables.arrID, GlobalVariables.arrLang);					
					break;
			}
		}
	
		/**
		 * @author Daisy
		 * @usage This function is used to get CurrUserBet
		 */
		public function callGetCurrUserBet():void {
			this.ncId.call("currUserBet", new Responder(successCallFMS, failCallFMS), stageInfo.userInfo.sessionId, stageInfo.userInfo.roomId);
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is called from FMS, return result CurrUserBet. Override in every Game this function.
		 */
		public function setPlaceBet1(result:String):void {	
			
		}
		/**
		 * @author	Bamboo
		 */
		public function callGetVODId():void {
			this.ncId.call("getVODId", new Responder(successCallFMS, failCallFMS), stageInfo.userInfo.sessionId, stageInfo.userInfo.roomId);
			//trace("callGetVODId" + "ss:"+stageInfo.userInfo.sessionId +":"+ stageInfo.userInfo.roomId);
		}
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		public function setVODId(result:String):void {
			//trace("haaaaaa" + result);
		}
		
		public function setAllTableRoutesbyTable_Bac(result:String):void {
			
		}
		
		public function setOwnUserBet(result:String, seatId:String):void {
			
		}
		
		public function setCardResultDelay(cardCode:String, where:String, instanceName:String):void {
			
		}
		public function setCardResult(cardCode:String, where:String, instanceName:String) {
			
		}
		
	    public function setAskRoute(result:String):void {
			
		}
		public function setErrorMessage(result:String):void {
			trace("setErrorMessage:" + result);
		}		
		
		public function setAskVirtualRoute(result:String, type:String):void {			
			
		}
		
		/**
		 * @author Daisy
		 * @usage Close Connecttion
		 */
		public function closeConnect():void {	
			this.nc.close();
			this.ncId.close();
			this.sndCtr.stopSound();
		}
		/**
		 * @author	Bamboo
		 */
		public function updateVolumeGame():void {
			this.sndCtr.setVolumnSound(GlobalVariables.volumeSounGame);
		}
		public function lockVolumeGame():void {
			this.sndCtr.stopSound();
		}
		public function unClockVolumeGame():void {
			this.sndCtr.unLockSound();
		}
		public function showPasswordResult(result:String):void {
			trace("showPasswordResult:" + result);
		}
		
		public function memberStartBetInsurance(result:String, countDownSecond:int):void { }
		public function memberStopBetInsurance(result:String):void {
			this.currentView.initStopGame();			
		}
		
		public function updateVideoPath(fmsVideo:String):void {
			
			var temp:String;
			switch(this.stageInfo.userInfo.roomId) {
				case "9":
				case "6":
				case "20":
					temp = fmsVideo + "@" + "grd-t03-live1";
					break;
				case "21":
					temp = fmsVideo + "@" + "gmg-t01-live2";
					break;	
				case "22":
					temp = fmsVideo + "@" + "gmg-l01-live2";
					break;
				case "23":
					temp = fmsVideo + "@" +  "gmg-t02-live2";
					break;
				case "24":
					temp = fmsVideo + "@" +  "grd-t04-live1";
					break;
				case "25":
					temp = fmsVideo + "@" + "grd-f01-live1";
					break;
				
				case "26":
					temp = fmsVideo + "@" +  "gmg-f01-live2";
					break;	
				case "27":
					temp = fmsVideo + "@" +  "grd-l01-live2";
					break;
				case "28":
					temp = fmsVideo + "@" +  "grd-s01-live1";
					break;
				
				case "29":
					temp = fmsVideo + "@" +  "grd-r01-live1";
					break;
			}
			
			GlobalVariables.fmsChannel = temp;
			this.currentView.updateVideoPath(GlobalVariables.fmsChannel);	
			
		}
		
	}
	
}